#include "DinoEngine.h"


DinoEngine::DinoEngine(void)
{
	this->m_bIsActive = false;
}


DinoEngine::~DinoEngine(void)
{
}

bool DinoEngine::Initialize(int gl_ver, void *nativeWindow)
{
	// init render system
	if(m_displayDevice.Initialize(gl_ver, nativeWindow) == false)
		return false;

	return true;
}

void DinoEngine::Work()
{
	if(m_bIsActive)
	{
		m_displayDevice.PreRender();
		m_displayDevice.Render();
		m_displayDevice.PostRender();

		Update((float)m_timer.GetDeltaSeconds() / 1000.0f);

		// timer tick
		m_timer.Tick();
	}
}

DisplayDevice_EGL &DinoEngine::GetDisplayDevice()
{
	return this->m_displayDevice;
}

void DinoEngine::Terminate()
{
	this->m_displayDevice.Terminate();
}

void DinoEngine::SetActive(bool active)
{
	this->m_bIsActive = active;
}

DTimer & DinoEngine::GetTimer()
{
	return m_timer;
}

void DinoEngine::SendEvent(ENGINE_EVENT evt)
{
	switch(evt)
	{
	case EE_CAMERA_START_MOVE_FORWARD:
		m_mainCamera.startMove(true, -5.0f);
		break;

	case EE_CAMERA_START_MOVE_BACKWARD:
		m_mainCamera.startMove(true, 5.0f);
		break;

	case EE_CAMERA_START_STRAFE_RIGHT:
		m_mainCamera.startStrafe(true, -5.0f);
		break;

	case EE_CAMERA_START_STRAFE_LEFT:
		m_mainCamera.startStrafe(true, 5.0f);
		break;

	case EE_CAMERA_START_PITCH_DOWN:
		m_mainCamera.startPitch(true, 2.0f);
		break;

	case EE_CAMERA_START_PITCH_UP:
		m_mainCamera.startPitch(true, -2.0f);
		break;

	case EE_CAMERA_START_YAW_RIGHT:
		m_mainCamera.startYaw(true, 2.0f);
		break;

	case EE_CAMERA_START_YAW_LEFT:
		m_mainCamera.startYaw(true, -2.0f);
		break;

	case EE_CAMERA_STOP_STRAFE:
		m_mainCamera.startStrafe(false);
		break;

	case EE_CAMERA_STOP_MOVE:
		m_mainCamera.startMove(false);
		break;

	case EE_CAMERA_STOP_PITCH:
		m_mainCamera.startPitch(false);
		break;

	case EE_CAMERA_STOP_YAW:
		m_mainCamera.startYaw(false);
		break;
	}
}

void DinoEngine::Update(float delta)
{
	m_mainCamera.Update(delta);
}